package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsActionNotTimeout;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.viewhelper.CarAutoTerminalManageViewHelper;

/**
 * 自主打印-二手车上牌
 * 
 */
public class CarAutoTerminalSecondHandInputAction extends TmsActionNotTimeout {
	
	private Logger logger = Logger.getLogger(CarAutoTerminalSecondHandInputAction.class);
	private static final String BACKFLAG = "backFlag";
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		CarAutoTerminalManageViewHelper view = new CarAutoTerminalManageViewHelper();
		
		//车牌前两位 ( 前两位是文本显示，值为当前市场所设置车牌前两位，值为系统功能配置表（defLicensePlate）的参数名（confKey）为“defLicensePlate”的参数值
		String lPlate = Registry.getConfig(TmsConstants.TMS_DEFLICENSEPLATE_KEY);
		view.setDefLicensePlate(lPlate.substring(0,2));
		// 车颜色
		String licensePlateCol = uc.getParameter("licensePlateCol");
		if(StringUtil.isNullOrBlank(licensePlateCol)){
			view.setLicensePlateCol("1");
		}
		else {
			view.setLicensePlateCol(licensePlateCol);
		}
		// check状态flag
		String checkStatus = uc.getParameter("checkStatus");
		if(StringUtil.isNullOrBlank(checkStatus)){
			view.setCheckStatus("99");
		}
		
		String type = uc.getParameter("type");
		String licensePlateLast = uc.getParameter("licensePlateLast");
		String lcPrintBsFlag = uc.getParameter("lcPrintBsFlag");
		view.setLcPrintBsFlag(lcPrintBsFlag);
		// 设定页面值
		if (!StringUtil.isNullOrBlank(licensePlateLast) && !"1".equals(String.valueOf(uc.getAttribute(BACKFLAG)))) {
			licensePlateLast = new String(licensePlateLast.getBytes("ISO8859-1"), "UTF-8");
			view.setLicensePlateLast(licensePlateLast);
			view.setLicensePlate(view.getDefLicensePlate() + view.getLicensePlate());
			uc.removeAttribute(BACKFLAG);
		}
		
//		String dataFlg = request.getParameter("dataFlg");
//		if(!StringUtil.isNullOrBlank(dataFlg)
//				&& dataFlg.equals("1")) {
//			view.setBackFlag(2);
//		}
//		// “1：查验照相、2：流程受理、18：退办继续受理”
//		view.setStatus(request.getParameter("status"));
		view.setType(type);
		request.setAttribute(VIEWHELP, view);	
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}
}
